package org.icsdt.sp;

import java.util.List;

import org.icsdt.sp.domain.Millenium;
import org.icsdt.sp.domain.Perito;
import org.icsdt.sp.service.BDService;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class PeritoAdapter extends ArrayAdapter<Perito> {
    private final Context context;

    public PeritoAdapter(Context context, List<Perito> items) {
	super(context, android.R.layout.simple_dropdown_item_1line, items);
	this.context = context;	
    }
   
    public View getView(int posicao, View view, ViewGroup parent) {
	LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	view = inflater.inflate(R.layout.perito_item, null);
	Perito p = getItem(posicao);
	TextView tNome = (TextView) view.findViewById(R.id.tNome);
	TextView tMatricula = (TextView) view.findViewById(R.id.tMatricula);
	TextView tSecao = (TextView) view.findViewById(R.id.tSecao);
	// Agora que temos a view atualizada os valores
	tNome.setText(p.nome);
	tMatricula.setText(p.matricula);
	BDService.loadSecao(p.secao);
	tSecao.setText(p.secao.nome);
	return view;
    }
    
}
